﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Aulac.Rsc.Bss;
using Aulac.Rsc.Bss.Tags;
using Aulac.Global.Common;

namespace Aulac.Client.Bss.WinForm.CapAss
{
    public partial class FormList_Dm_CapAss : Aulac.Client.Controls.Forms.Bss.FormEmsListItemsData
    {
        private FormDlgCapAss mFormDlgCapAss = null;
        private string mTitleName = "";
        public FormList_Dm_CapAss()
        {
            InitializeComponent();
            grdList.DataSource = new Aulac.Client.Data.Bss.DataSet.Catalog.Dm_CapAssDataTable();
            string strTitleName = this.GetTileDmTypesName(Dm_TbName.Dm_CapAss);
            if (!ValueHelper.isEmpty(strTitleName))
            {
                mTitleName = strTitleName;
                this.Text = Aulac.Global.Common.StringHelper.ReplaceIndex(strTitleName.ToLowerInvariant(), strTitleName.Substring(0, 1).ToLower(), strTitleName.Substring(0, 1).ToUpper(), 0);
            }
        }

        
       
        #region override Methods
        public override void OnFormLoad()
        {
            try
            {
                base.OnFormLoad();
                grdList.ClearColumsShow();
                //grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "STT", ColName = tagItems.CapAss.CapAssPrkID, DisplayIndex = 0 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Mã tài sản", ColName = tagItems.CapAss.CapAssID, DisplayIndex = 0 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Tên tài sản", ColName = tagItems.CapAss.CapAssName, DisplayIndex = 1 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Mã nhóm", ColName = tagItems.CapAssGrp.CapAssGrpID, DisplayIndex = 2 });
                //grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Giá bán", ColName = tagItems.CapAss.PriceSell, DisplayIndex = 3 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Đã phát sinh quá trình xử lý", ColName = tagItems.CapAss.IsActive, DisplayIndex = 3 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Mã mặt hàng", ColName = tagItems.CapAss.ItemPrkID, DisplayIndex = 4 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Nguyên giá", ColName = tagItems.CapAss.OriginalPrice, DisplayIndex = 5 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Tình trạng", ColName = tagItems.CapAss.StatePrkID, DisplayIndex = 6 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Số Serial", ColName = tagItems.CapAss.Serial, DisplayIndex = 7 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Mã nhân viên quản lý", ColName = tagItems.CapAss.StaffPrkID, DisplayIndex = 8 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Mã nhà cung cấp", ColName = tagItems.CapAss.ProviderPrkID, DisplayIndex = 9 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Mã bộ phận quản lý", ColName = tagItems.CapAss.DeptPrkID, DisplayIndex = 10 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Thời gian bảo hành", ColName = tagItems.CapAss.Warranty, DisplayIndex = 11 });
                grdList.AddColumnShow(new Aulac.UtilityTools.ColumnGridViewInfo() { ColCaption = "Mô tả", ColName = tagItems.CapAss.Describe, DisplayIndex = 12 });
                
                //grdList.Columns[tagItems.CapAss.CapAssName].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
        protected override void OnSetDataSource(out object pDataSource, out string pTableName)
        {
            pDataSource = null;
            pTableName = TableNames.Dm_CapAss;
        }
        protected override void OnAddParamsQuery()
        {
            //AddParamQuery(tagItems.Countries.IsActive, tagItems.Countries.IsActive, 1);// gia tri can truy van co isactive = 1;
        }

        protected override string OnCreateQueryString()
        {
            string sqlQuery = string.Format("SELECT dbo.Dm_CapAss.*, dbo.Dm_CapAssGrp.CapAssGrpID FROM dbo.Dm_CapAss LEFT OUTER JOIN dbo.Dm_CapAssGrp ON dbo.Dm_CapAss.CapAssGrpPrkID = dbo.Dm_CapAssGrp.CapAssGrpPrkID");
            //string sqlQuery = string.Format("SELECT C.{0}, CGrp.{1}", "*", tagItems.CapAssGrp.CapAssGrpID);
            //sqlQuery += string.Format(" FROM {0} C INNER JOIN", TableNames.Dm_CapAss);
            //sqlQuery += string.Format(" {0} CGrp ON C.{1} = CGrp.{2}", TableNames.Dm_CapAssGrp, tagItems.CapAss.CapAssGrpPrkID, tagItems.CapAssGrp.CapAssGrpPrkID);
            //sqlQuery += string.Format(" INNER JOIN {0} CT ON C.{1} = CT.{2}", TableNames.Dm_CapAssType, tagItems.CapAss.CapAssTypePrkID, tagItems.CapAssType.CapAssTypePrkID);
            return sqlQuery;
        }

        protected override void OnListShowDetailVoucher()
        {
            ProcessFormCmd(Aulac.Global.Enums.FormModes.ViewMode);
        }
        protected override void OnListAddNewVoucher()
        {
            ProcessFormCmd(Aulac.Global.Enums.FormModes.NewMode);
            mFormDlgCapAss.ShowDialog();
        }
        protected override void OnListEditVoucher()
        {
            ProcessFormCmd(Aulac.Global.Enums.FormModes.EditMode);
        }
        protected override void OnListDelDataVoucher()
        {
            ProcessFormCmd(Aulac.Global.Enums.FormModes.DelMode);
        }
        #endregion
        #region Methods
        private void ProcessFormCmd(Aulac.Global.Enums.FormModes pFormmode)
        {
            try
            {
                if (mFormDlgCapAss == null)
                {
                    mFormDlgCapAss = new FormDlgCapAss();
                    FormDataItemsCmd = mFormDlgCapAss;
                    mFormDlgCapAss.ExitComplated += new EventHandler(FrmDlgCapAss_ExitComplete);                                
                }                
                if (!ValueHelper.isEmpty(mTitleName))
                    mFormDlgCapAss.TitleName = mTitleName;
                mFormDlgCapAss.CapAssPrkID = grdList.GetValue(grdList.SelectedGridRowView, tagItems.CapAss.CapAssPrkID);
                mFormDlgCapAss.FormMode = pFormmode;

                if (pFormmode == Aulac.Global.Enums.FormModes.ViewMode)
                {
                    mFormDlgCapAss.ShowDetailVoucher();
                }
                else if (pFormmode == Aulac.Global.Enums.FormModes.NewMode)
                {
                    mFormDlgCapAss.CapAssPrkID = "";
                    mFormDlgCapAss.AddNewVoucher();
                }
                else if (pFormmode == Aulac.Global.Enums.FormModes.EditMode)
                {
                    mFormDlgCapAss.EditVoucher();
                }
                else if (pFormmode == Aulac.Global.Enums.FormModes.DelMode)
                {
                    mFormDlgCapAss.DeleteCapAss();
                    this.RefreshList();
                    return;
                }
                mFormDlgCapAss.ShowDialog();
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
        private void FrmDlgCapAss_ExitComplete(object sender, EventArgs e)
        {
            this.CancelTransaction();
            this.grdList.ClearDataContainer();
            this.RefreshList();
        }
        #endregion
    }
}
